package pl.enigmatic.parser.metadata;

import pl.enigmatic.parser.xml.ObjectCreator;
import pl.enigmatic.parser.xml.Parser;
import pl.enigmatic.parser.xml.ParsingInfo;


@SuppressWarnings("rawtypes")
public class ValueExtension extends MetadataParserExtension implements ObjectCreator {

	public static ValueExtension instance = new ValueExtension();

	public ValueExtension() {
		super(Metadata.VALUE);
	}

	@Override
	public boolean parseMetadata(final Object target, final ParsingInfo<?> info, final String name) {
		return true;
	}

	@SuppressWarnings({ "unchecked" })
	@Override
	public Object createInstance(final ParsingInfo info) {
		if (info.containsMetadata(getBase())) {
			final Parser<?>.XMLParserFinder finder = info.getParser().findMarkup(info.getMetadata(getBase()), info.getTarget());
			if (finder.isMarkup()) { return finder.getMarkup().createInstance(finder.getProps(), info); }
		}
		return null;
	}
}
